//package com.bluemsun.naturallanguageprocessing.Aspect;
//
//import com.bluemsun.naturallanguageprocessing.entity.User;
//import com.bluemsun.naturallanguageprocessing.exception.ExceedAuthoritiesException;
//import com.bluemsun.naturallanguageprocessing.exception.UserAuthoritiesException;
//import com.bluemsun.naturallanguageprocessing.exceptionHandler.AuthoritiesException;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.*;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Arrays;
//
///**
// * @author ：hj
// * @date ：Created in 2020/11/11 15:17
// * @description：登录拦截注入
// * @modified By：
// * @version: $
// */
//@Aspect
//@Component
//public class WebLogAspect {
//
//    private final Logger logger = LoggerFactory.getLogger(com.bluemsun.naturallanguageprocessing.Aspect.WebLogAspect.class);
//
//    @Pointcut("execution( public * com.bluemsun.naturallanguageprocessing.controller.UserController.*(..))")
//    public void controllerLog(){
//    };
//
//    @Before("controllerLog()") //在切入点的方法run之前要干的
//    public void logBeforeController(JoinPoint joinPoint) {
//
//
//        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();//这个RequestContextHolder是Springmvc提供来获得请求的东西
//        HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest();
//
//        // 记录下请求内容
//        logger.info("################URL : " + request.getRequestURL().toString());
//        logger.info("################HTTP_METHOD : " + request.getMethod());
//        logger.info("################IP : " + request.getRemoteAddr());
//        logger.info("################THE ARGS OF THE CONTROLLER : " + Arrays.toString(joinPoint.getArgs()));
//
//        //下面这个getSignature().getDeclaringTypeName()是获取包+类名的   然后后面的joinPoint.getSignature.getName()获取了方法名
//        logger.info("################CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//        //logger.info("################TARGET: " + joinPoint.getTarget());//返回的是需要加强的目标类的对象
//        //logger.info("################THIS: " + joinPoint.getThis());//返回的是经过加强后的代理类的对象
//        if(joinPoint.getSignature().getName().equals("login")||joinPoint.getSignature().getName().equals("register")){
//
//        }
//        else {
//          User isExistUser = (User)request.getSession().getAttribute("user");
//          if(isExistUser==null){
//              throw new UserAuthoritiesException("用户未登录");
//          }
//        }
//        if (joinPoint.getSignature().getName().equals("selectUser")||joinPoint.getSignature().getName().equals("selectAllUser")){
//            User isExistUser = (User)request.getSession().getAttribute("user");
//            if(isExistUser.getRole()==0){
//                throw new ExceedAuthoritiesException("用户越权");
//            }
//        }
//
//    }
//    @After(value = "controllerLog()")
//    public void after() {
//        logger.info("记录操作后");
//    }
//
//    /**
//     * 打印返回的内容
//     * @param object
//     */
//    @AfterReturning(value = "controllerLog()", returning = "object")
//    public void afterReturn(Object object) {
//        logger.info("object={}", object);
//    }
//}
